<?php
declare (strict_types = 1);

namespace app\admin\model;

/**
 * Class SystemUser
 * @package app\admin\model
 */
class SystemUser extends BaseModel
{
    public function group()
    {
        return $this->hasOne('SystemGroup','id','group_id');
    }
    public static function getUserInfoByID($id){
        return self::with('group')->
        field('id,group_id,username,key,name,nickname,contact_phone,status,login_times,create_time,last_time')
            ->find($id);
    }
    public static function getUserByID($id){
        return self::field('id,username,password,key,name,nickname,contact_phone,status')
            ->find($id);
    }

    public static function getUserByUsername($username){
        return self::field('id,username,password,key,nickname,login_times,login_ip,last_time')
            ->where(['status' => 1, 'username' => $username])
            ->find();
    }
    public static function getAllUserInfo(){
        return self::with('group')
            ->field('id,group_id,username,name,nickname,status,login_times,login_ip,last_time')
            ->order('last_time DESC,id')
            ->select();
    }
}
